<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  function myEach(arr, fn) {
    // var arr = [2,8,4,6,5,7,9,3,1];
    // var fn = function(item,index,array){ // 形式参数(对应接收函数在调用时实际传入的值)
    //     console.log(item,index,array);
    // }
    // var arr = [9,1,7,3,4,6,8,2,5];
    // var fn = function(item){
    //     console.log(item);
    // }

    for (var i = 0; i < arr.length; i++) {
      var item = arr[i];  //循环的当前元素
      var index = i;    // 循环的当前下标
      var array = arr;  //原数组
      fn(item, index, array); // 实际参数 (函数调用时实际传入的值)
    }
  }

  // var list = [9,1,7,3,4,6,8,2,5];
  // console.log("原数组",list);
  // myEach([9,1,7,3,4,6,8,2,5],function(item){
  //     console.log(item);
  // })

  function myMap(arr, fn) {
    // var arr = [2,8,4,6,5,7,9,3,1];
    // var fn = function(item,index,array){ // 形式参数(对应接收函数在调用时实际传入的值)
    //     console.log(item,index,array);
    // }

    var brr = [];
    for (var i = 0; i < arr.length; i++) {
      var item = arr[i];  //循环的当前元素
      var index = i;    // 循环的当前下标
      var array = arr;  //原数组
      var result = fn(item, index, array); // 实际参数 (函数调用时实际传入的值)
      brr.push(result);
    }
    return brr;
  }

  var list = [9, 1, 7, 3, 4, 6, 8, 2, 5];
  console.log("原数组", list);
  var res = myMap([9, 1, 7, 3, 4, 6, 8, 2, 5], function (item) {
    console.log(item);
    return parseInt((item * 3 + 5) / 2)
  })
  console.log(res);



</script>

</html>